import { Opt } from '__com/Opt.js'
import ruleOpt from '@/option/rule.js'
import cityOpt from '@/option/city.js'
import apiMgr from './index'
const type = null
export class editOpt extends Opt {
  constructor(fun) {
    super(fun)
  }

  create() {
    return [
      {
        placeholder: '变更前项目信息',
        visible: this.getNum() != null && this.getNum() != 7 && this.getNum() != 8,
        text: {
          className: 'info-label-title'
        }
      },
      // 有效期
      {
        placeholder: '变更前有效期',
        visible: this.getNum() == 7,
        text: {
          className: 'info-label-title'
        }
      },
      {
        title: '项目起始日期',
        key: 'effectStartDateLast',
        visible: this.getNum() == 7,
        text: {}
      },
      {
        title: '项目结束日期',
        key: 'effectEndDateLast',
        visible: this.getNum() == 7,
        text: {}
      },

      {
        title: '有效天数',
        key: 'effectDayLast',
        visible: this.getNum() == 7,
        group: [
          {
            key: 'effectDayLast',
            col: 4,
            text: {}
          },
          {
            placeholder: '天',
            col: 4,
            text: {}
          }
        ]
      },
      {
        title: '剩余天数',
        key: 'effectSurplusDayLast',
        visible: this.getNum() == 7,
        group: [
          {
            key: 'effectSurplusDayLast',
            col: 4,
            text: {}
          },
          {
            placeholder: '天',
            col: 4,
            text: {}
          }
        ]
      },
      {
        placeholder: '变更后有效期',
        visible: this.getNum() == 7,
        text: {
          className: 'info-label-title'
        }
      },
      {
        placeholder: '该项目为“生效中”项目，“起始日期”不可变更',
        visible: this.getTenantStatus() == 3 && this.getNum() == 7,
        text: {
          color: '#ccc',
          marginLeft: '30px'
        }
        // data: {
        //   from: (info) => {
        //     return `<span><Icon type="ios-alert" color="#2D61F4" class="tips_icon" /> 该项目为“生效中”项目，“起始日期”不可变更 <Icon type="ios-alert" color="#2D61F4" class="tips_icon" /> </span>`
        //   }
        // }
      },
      {
        title: '项目起始日期',
        key: 'effectStartDate',
        disabled: this.getTenantStatus() == 3,
        visible: this.getNum() == 7,
        placeholder: '请选择开始时间',
        xl: 4,
        date: {
          type: 'date',
          format: 'yyyy-MM-dd',
          disabled: (date) => {
            return date && date.valueOf() < Date.now() - 86400000
          }
        },
        change: (val) => {
          this.dataChange()
        },
        rules: [ruleOpt.required('请选择开始时间')]
      },
      {
        title: '项目结束日期',
        key: 'effectEndDate',
        visible: this.getNum() == 7,
        placeholder: '请选择结束时间',
        xl: 4,
        date: {
          type: 'date',
          format: 'yyyy-MM-dd',
          disabled: (date) => {
            return date && date.valueOf() < Date.now() - 86400000
          }
        },
        change: (val) => {
          this.dataChange()
        },
        rules: [ruleOpt.required('请选择结束时间')]
      },
      {
        title: '有效天数',
        key: 'effectDay',
        visible: this.getNum() == 7,
        group: [
          {
            key: 'effectDay',
            col: 4,
            text: {}
          },
          {
            placeholder: '天',
            col: 4,
            text: {}
          }
        ]
      },
      {
        title: '剩余天数',
        key: 'effectSurplusDay',
        visible: this.getNum() == 7,
        group: [
          {
            key: 'effectSurplusDay',
            col: 4,
            text: {}
          },
          {
            placeholder: '天',
            col: 4,
            text: {}
          }
        ]
      },

      // 冻结
      {
        placeholder: '冻结前有效期',
        visible: this.getNum() == 8,
        text: {
          className: 'info-label-title'
        }
      },
      {
        title: '项目起始日期',
        key: 'effectStartDateLast',
        visible: this.getNum() == 8,
        text: {}
      },
      {
        title: '项目结束日期',
        key: 'effectEndDateLast',
        visible: this.getNum() == 8,
        text: {}
      },

      {
        title: '有效天数',
        key: 'effectDayLast',
        visible: this.getNum() == 8,
        group: [
          {
            key: 'effectDayLast',
            col: 4,
            text: {}
          },
          {
            placeholder: '天',
            col: 4,
            text: {}
          }
        ]
      },
      {
        title: '剩余天数',
        key: 'effectSurplusDayLast',
        visible: this.getNum() == 8,
        group: [
          {
            key: 'effectSurplusDayLast',
            col: 4,
            text: {}
          },
          {
            placeholder: '天',
            col: 4,
            text: {}
          }
        ]
      },
      {
        placeholder: '冻结期限设置',
        visible: this.getNum() == 8,
        text: {
          className: 'info-label-title'
        }
      },
      {
        placeholder: this.freeTips(),
        visible: this.freeTips() && this.getNum() == 8,
        text: {
          color: '#999',
          marginLeft: '30px'
        }
      },
      {
        placeholder: '该项目为“冻结中”项目，“起始日期”不可变更',
        visible: this.getFreezeStartDate() && this.getNum() == 8,
        text: {
          color: '#999',
          marginLeft: '30px'
        }
      },
      {
        title: '冻结起始日期',
        key: 'freezeStartDate',
        visible: this.getNum() == 8,
        disabled: this.getFreezeStartDate(),
        placeholder: '请选择开始时间',
        xl: 4,
        date: {
          type: 'date',
          format: 'yyyy-MM-dd',
          disabled: (date) => {
            return date && date.valueOf() < Date.now() - 86400000
          }
        },
        change: (val) => {
          this.dataFreeChange()
        },
        rules: [ruleOpt.required('请选择开始时间')]
      },
      {
        title: '冻结结束日期',
        key: 'freezeEndDate',
        visible: this.getNum() == 8,
        placeholder: '请选择结束时间',
        xl: 4,
        date: {
          type: 'date',
          format: 'yyyy-MM-dd',
          disabled: (date) => {
            return date && date.valueOf() < Date.now() - 86400000
          }
        },
        change: (val) => {
          this.dataFreeChange()
        }
      },
      {
        title: '冻结天数',
        key: 'freezeDay',
        visible: this.getNum() == 8,
        group: [
          {
            key: 'freezeDay',
            col: 4,
            text: {}
          },
          {
            placeholder: '天',
            col: 4,
            text: {}
          }
        ]
      },

      {
        placeholder: '解冻后有效期',
        visible: this.getNum() == 8,
        text: {
          className: 'info-label-title'
        }
      },
      {
        title: '项目起始日期',
        key: 'effectStartDateLast',
        visible: this.getNum() == 8,
        text: {}
      },
      {
        title: '项目结束日期',
        key: 'freezeEndDateAddEffectSurplusDay',
        visible: this.getNum() == 8,
        text: {}
      },
      // 冻结

      // 项目信息

      {
        title: '项目名称',
        key: 'tenantNameLast',
        visible: this.getNum() == 2,
        text: {}
      },
      {
        title: '项目合同主体',
        key: 'companyNameLast',
        visible: this.getNum() == 3,
        text: {}
      },
      {
        title: '所属人名称',
        key: 'belongUserNameLast',
        visible: this.getNum() == 4 || this.getNum() == 5,
        text: {}
      },
      {
        title: '所属人手机号',
        key: 'belongUserPhoneLast',
        visible: this.getNum() == 5,
        text: {}
      },
      {
        title: '所属人城市',
        key: 'cityLast',
        visible: this.getNum() == 6,
        text: {}
      },
      {
        placeholder: '变更后项目信息',
        visible: this.getNum() != null && this.getNum() != 7 && this.getNum() != 8,
        text: {
          className: 'info-label-title'
        }
      },
      {
        title: '项目名称',
        visible: this.getNum() == 2,
        key: 'tenantName',
        placeholder: '请输入项目名称',
        input: {
          maxlength: 20
        },
        rules: [ruleOpt.required('项目名称不能为空')]
      },

      {
        title: '合同主体',
        key: 'companyId',
        visible: this.getNum() == 3,
        load: (o) => {
          apiMgr.getSysCompanyForWeb().then((res) => {
            console.log(res, '111')
            o.select.options = res
          })
        },
        select: {
          options: []
        },
        change: (val) => {
          console.log(val, '项目主体')
          this.chooseCompanyName(val.editValue)
        },
        rules: [ruleOpt.required('项目主体不能为空')]
      },
      {
        title: '所属人姓名',
        key: 'belongUserName',
        placeholder: '请输入所属人姓名',
        visible: this.getNum() == 4,
        input: {
          maxlength: 20
        },
        rules: [ruleOpt.required('所属人姓名不能为空')]
      },
      {
        title: '所属人手机号码',
        key: 'belongUserPhone',
        placeholder: '请输入所属人手机号码',
        visible: this.getNum() == 5,
        input: {
          maxlength: 11
        },
        rules: [ruleOpt.required('所属人手机号不能为空'), ruleOpt.phone()]
      },
      cityOpt.cityCascader(
        {
          title: '所属城市',
          key: 'peopleCity',
          visible: this.getNum() == 6,
          changeOnSelect: false,

          change: (v) => {
            if (v.editValue.length) {
              this.chooseCity(v.editValue)
            } else {
            }
          },
          rules: [
            {
              type: 'array',
              required: true,
              message: '所属城市不能为空',
              trigger: 'blur'
            }
          ]
        },
        3
      ),
      {
        placeholder: '变更说明',
        visible: this.getNum() != null,
        text: {
          className: 'info-label-title'
        }
      },
      {
        title: '',
        key: 'changeDescription',
        placeholder: '请输入变更说明',
        visible: this.getNum() != null,
        input: {
          type: 'textarea',

          showWordLimit: true,
          maxlength: 200,
          autosize: {
            minRows: 3,
            maxRows: 5
          }
        }
      }
    ]
  }
}

export class editOpt1 extends Opt {
  constructor(fun) {
    super(fun)
  }

  create() {
    return [
      {
        // placeholder: '变更前项目信息',
        // visible: this.getNum() != null && this.getNum() != 7 && this.getNum() != 8,
        // text: {
        //   className: 'info-label-title'
        // }
      }
    ]
  }
}
